import MySQLdb

class Cliente:
    
    def __init__(self,nome="",cpf="",telefone="",endereco="",email=""):
        self.idCliente = ""
        self.nome = nome
        self.cpf = cpf
        self.telefone = telefone
        self.endereco = endereco
        self.email = email

    def getIdCliente(self):
        return self.idCliente

    def setIdCliente(self,novoId):
        self.idCliente = novoId


    def getNome(self):
        return self.nome

    def setNome(self,novoNome):
        self.nome = novoNome


    def getCpf(self):
        return self.cpf

    def setCpf(self,novoCpf):
        self.cpf = novoCpf



    def getTelefone (self):
        return self.telefone

    def setTelefone (self,novoTelefone):
        self.telefone = novoTelefone



    def getEndereco (self):
        return self.endereco

    def setEndereco (self,novoEndereco):
        self.endereco = novoEndereco



    def getEmail(self):
        return self.email

    def setEmail (self,novoEmail):
        self.email = novoEmail

    def insert(self):
        db = MySQLdb.connect("localhost","root","","gtec" )
        cursor = db.cursor()
        
        cursor.execute("INSERT INTO cliente (nome,cpf,telefone,endereco,email) VALUES ('"+self.nome+"','"+self.cpf+"','"+self.telefone+"','"+self.endereco+"','"+self.email+"')")
        db.commit()
        
    def update(self):
        db = MySQLdb.connect("localhost","root","","gtec" )
        cursor = db.cursor()
        
        cursor.execute("UPDATE cliente SET nome = '"+self.nome+"',cpf = '"+self.cpf+"',telefone = '"+self.telefone+"',\
                        endereco = '"+self.endereco+"',email = '"+self.email+"' WHERE idCliente = '"+str(self.idCliente)+"'")
        db.commit()

    def remover(self):
        db = MySQLdb.connect("localhost","root","","gtec" )
        cursor = db.cursor()
        cursor.execute("DELETE FROM cliente WHERE IdCliente = '"+str(self.idCliente)+"'")
        db.commit()
        
    def load(self):
        db = MySQLdb.connect("localhost","root","","gtec" )
        cursor = db.cursor()
                       
        cursor.execute("SELECT * FROM cliente WHERE IdCliente ='"+str(self.idCliente)+"'")
        if(cursor.rowcount == 0):
            return False
        else:
            pesq = cursor.fetchall()
            print "\n|ID |"
            for coluna in pesq: print  "|",coluna[0],"|" ," Nome: ",coluna[1], "\n CPF: ",coluna[2] ,\
                "\n Telefone: ",coluna[3] , "\n Endereco: ",coluna[4] ,"\n Email: ",coluna[5]
        db.commit()


